<?php

namespace App\Http\Controllers\cms;

use App\Engine\BaseController;
use App\Http\Validate\ImageCategoryValidate;
use App\Models\ImageCategory as ImageCategoryModel;
use function app\Utils\go;

class ImageCategory extends BaseController
{

    /**获取图片分类
     * @return array
     */
    public function get()
    {
        return go(ImageCategoryModel::with('img')->get());
    }

    /**更新图片分类
     * @return array
     * @throws \Illuminate\Validation\ValidationException
     */
    public function update()
    {
        $this->validate($this->request,ImageCategoryValidate::$rule,ImageCategoryValidate::$message);
        return go(ImageCategoryModel::update_category($this->post));
    }

    /**添加图片分类
     * @return array
     * @throws \Illuminate\Validation\ValidationException
     */
    public function insert()
    {
        $this->validate($this->request,ImageCategoryValidate::$rule,ImageCategoryValidate::$message);
        return go(ImageCategoryModel::insert_category($this->post));
    }

    /**删除图片
     * @return array
     */
    public function del()
    {
        return go(ImageCategoryModel::find($this->get['id'])->delete());
    }

}
